<?php 
//企业展示页面前台控制器
namespace Home\Controller;
use       Think\Controller;

class CompanyController extends Controller {
    /**
     * 前台首页
     */
    public function index() {
        $newslist = M('CompanyNews')->order('news_id desc')->select();
        $this->assign('newslist', $newslist);
        $this->display();
    }

    public function intro() {
        $this->display();
    }

    public function cat() {
        $this->display();
    }

    public function photo() {
        $this->display();
    }

    public function msg() {
        if (!($data = $this->postParam())) {
            $this->display();
        } else {
            $companymsg = M('CompanyMsg');
            $companymsg->msg_name = $data->name;
            $companymsg->msg_contact = $data->contact;
            $companymsg->msg_content = $data->content;
            $companymsg->msg_addtime = time();
            $companymsg->add();
            header('refresh:3;url=\''.U('/home/company').'\'');
            $this->feedback();
        }
    }

    public function feedback() {
        $this->display('feedback');
    }

    /**
     * 通过get方法获得的参数
     * @return mixed 有参数时返回标准对象，无参数时返回false
     */
    protected function getParam() {
        $data = I('get.');
        if (empty($data)) {
            return false;
        }
        foreach ($data as $k=>$v) {
            $data[$k] = trim($v);
        }
        return (object)$data;
    }

    /**
     * 通过post方法获得的参数
     * @return mixed 有参数时返回标准对象，无参数时返回false
     */
    protected function postParam() {
        $data = I('post.');
        if (empty($data)) {
            return false;
        }
        foreach ($data as $k=>$v) {
            $data[$k] = trim($v);
        }
        return (object)$data;
    }
}